package com.ruoyi.system.utils;

import com.alibaba.fastjson.JSON;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class MapUtils {

    public static List<Object> getList(Map map, String key){
        List<Object> list=null;
        if(map.containsKey(key)&&map.get(key)!=null){
            list= (List<Object>) map.get(key);
        }
        return list;
    }
    public static String GetString(Map map, String key){
        String result="";
        if(map.containsKey(key)&&map.get(key)!=null){
            result = map.get(key).toString();
        }
        return result;
    }
    public static int GetInt(Map map,String key,int def){
        int result=def;
        if(map.containsKey(key)&&map.get(key)!=null){
            try {
                result = new Integer(map.get(key).toString()) ;
            }
            catch(Exception e){

            }
        }
        return result;
    }
    public static long GetLong(Map map,String key,long def){
        long result=def;
        if(map.containsKey(key)&&map.get(key)!=null){
            try {
                result = new Long(map.get(key).toString()) ;
            }
            catch(Exception e){

            }
        }
        return result;
    }

    public static BigDecimal GetBigDecimal(Map map, String key, String def){
        BigDecimal result=new BigDecimal(def);
        if(map.containsKey(key)&&map.get(key)!=null){
            try {
                result = new BigDecimal(map.get(key).toString()) ;
            }
            catch(Exception e){

            }
        }
        return result;
    }
    public static double GetDouble(Map map, String key, double def){
        double result=def;
        if(map.containsKey(key)&&map.get(key)!=null){
            try {
                result = new Double(map.get(key).toString()) ;
            }
            catch(Exception e){

            }
        }
        return result;
    }

    public static String GetJsonString(Map map,String key){
        String result="";
        try {
            if(map.containsKey(key)&&map.get(key)!=null){
                result = JSON.toJSONString(map.get(key));
            }
        }
        catch (Exception ex){

        }
        return result;
    }
}
